import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		events: uni.getStorageSync('events') || []
	},
	mutations: {
		ADD_EVENT(state, event) {
			state.events.push(event)
			uni.setStorageSync('events', state.events)
		},
		REMOVE_EVENT(state, id) {
			state.events = state.events.filter(e => e.id !== id)
			uni.setStorageSync('events', state.events)
		}
	}
})

export default store